home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / visulztn / saoimage / saoimage.lha / csrdraw.c < prev    next >
C/C++ Source or Header  |  1991-01-05  |  4KB  |  142 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    csrdraw.c (Cursor Draw)
  6.  * Purpose:    Display and draw the software cursor
  7.  * Subroutine:    disp_cursor()            returns: void
  8.  * Subroutine:    erase_cursor()            returns: void
  9.  * Subroutine:    draw_cursor()            returns: void
  10.  * Subroutine:    draw_annuli()            returns: void
  11.  * Subroutine:    draw_point()
  12.  * Subroutine:    erase_point()
  13.  * Xlib calls:    XDrawLines(), XDrawRectangles()
  14.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  15.  *        You may do anything you like with this file except remove
  16.  *        this copyright.  The Smithsonian Astrophysical Observatory
  17.  *        makes no representations about the suitability of this
  18.  *        software for any purpose.  It is provided "as is" without
  19.  *        express or implied warranty.
  20.  * Modified:    {0} Michael VanHilst    initial version          4 June 1989
  21.  *        {1} MVH added text cursor support           1 Jan 1991
  22.  *        {n} <who> -- <does what> -- <when>
  23.  */
  24.  
  25. #include <stdio.h>        /*  stderr, NULL, etc.  */
  26. #include <X11/Xlib.h>        /*  X window stuff  */
  27. #include <X11/Xutil.h>        /*  X window manager stuff  */
  28. #include "hfiles/color.h"    /*  Cursor colors needed by Cursor.h  */
  29. #include "hfiles/cursor.h"    /*  Define cursor parameter structures  */
  30. #include "hfiles/constant.h"    /*  Define codes  */
  31.  
  32. extern struct colorRec color;    /*  Need to know color.gcset  */
  33.  
  34.  
  35. #ifdef ANSIC
  36. /*  Exported declarations must be centralized before ANSI C can be used  */
  37.  
  38. void        disp_cursor(    struct cursorRec *cursor);
  39. void        erase_cursor(    struct cursorRec *cursor);
  40. void        draw_cursor(    struct cursorRec *cursor, GCspec *draw);
  41. void        draw_annuli(    struct cursorRec *cursor, GCspec *draw);
  42.  
  43. #else
  44.  
  45.   GC set_gc();
  46.   void draw_annuli(), draw_cursor(), draw_point(), erase_point();
  47.   void draw_textcursor();
  48.  
  49. #endif
  50.  
  51.  
  52. /*  Subroutine:    disp_cursor
  53.  *  Purpose:    Draw the software cursor, if it is to be visible
  54.  */
  55. #ifdef ANSIC
  56. void disp_cursor ( struct cursorRec *cursor )
  57. #else
  58. void disp_cursor ( cursor )
  59.      struct cursorRec *cursor;
  60. #endif
  61. {
  62.   /*  If there are annuli, draw them  */
  63.   if( cursor->annuli ) {
  64.     draw_annuli(cursor, cursor->draw);
  65.   } else {
  66.     if( cursor->point_cnt || cursor->rectangle_cnt )
  67.       draw_cursor(cursor, cursor->draw);
  68.   }
  69. }
  70.  
  71.  
  72. /*  Subroutine:    erase_cursor
  73.  *  Purpose:    Undraw the cursor
  74.  */
  75. #ifdef ANSIC
  76. void erase_cursor ( struct cursorRec *cursor )
  77. #else
  78. void erase_cursor ( cursor )
  79.      struct cursorRec *cursor;
  80. #endif
  81. {
  82.   if( cursor->point_cnt || cursor->rectangle_cnt )
  83.     draw_cursor(cursor, &color.gcset.undraw);
  84. }
  85.  
  86.  
  87. /*  Subroutine:    draw_cursor
  88.  *  Purpose:    Draw a cursor as indicated
  89.  */
  90. #ifdef ANSIC
  91. void draw_cursor ( struct cursorRec *cursor, GCspec *draw )
  92. #else
  93. void draw_cursor ( cursor, draw )
  94.      struct cursorRec *cursor;
  95.      GCspec *draw;
  96. #endif
  97. {
  98.   GC gc;
  99.  
  100.   if( cursor->type == COP_Text ) {
  101.     draw_textcursor(cursor, draw);
  102.     return;
  103.   }
  104.   gc = set_gc(draw);
  105.   /*  Draw the cursor  */
  106.   if( cursor->point_cnt > 0 )
  107.     XDrawLines(cursor->win.display, cursor->win.ID, gc,
  108.            cursor->points, cursor->point_cnt, CoordModeOrigin);
  109.   else if( cursor->point_cnt < 0 )
  110.     XDrawSegments(cursor->win.display, cursor->win.ID, gc,
  111.           (XSegment *)cursor->points, -cursor->point_cnt);
  112.   if( cursor->rectangle_cnt )
  113.     XDrawRectangles(cursor->win.display, cursor->win.ID, gc,
  114.             cursor->rectangles, cursor->rectangle_cnt);
  115. }
  116.  
  117.  
  118. /*  Subroutine:    draw_annuli
  119.  *  Purpose:    Draw all annuli in specified color and function
  120.  */
  121. #ifdef ANSIC
  122. void draw_annuli ( struct cursorRec *cursor, GCspec *draw )
  123. #else
  124. void draw_annuli ( cursor, draw )
  125.      struct cursorRec *cursor;
  126.      GCspec *draw;
  127. #endif
  128. {
  129.   struct cursorRec *annulus;
  130.   GC gc;
  131.  
  132.   gc = set_gc(draw);
  133.   /*  Draw the cursor  */
  134.   annulus = cursor->next_annulus;
  135.   while( annulus != NULL ) {
  136.     if( annulus->point_cnt )
  137.       XDrawLines(annulus->win.display, annulus->win.ID, gc,
  138.          annulus->points, annulus->point_cnt, CoordModeOrigin);
  139.     annulus = annulus->next_annulus;
  140.   }
  141. }
  142.